package domain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Menu {

	public static String name1, name2;
	
	public void initMenu(){
        System.out.println("1. One Player");
        System.out.println("2. Two Player");
        System.out.println("3. Highscores");
        System.out.println("4. Settings");		
        System.out.println("5. About");
        System.out.println("0. Quit");
	
        int userInput = stringToInt(inputOutput("\nYou press the number 1 to play one player game " +
        		"because our main use case that we implement in this code is that" +
        		"Other will be exited."));
        
        if(userInput == 1) selectLevel();
        if(userInput == 2) setTwoPlayer();
        if(userInput == 3) wrongChoice();
        if(userInput == 4) wrongChoice();
        if(userInput == 5) wrongChoice();
        if(userInput == 0) System.exit(0);
	}
	
    private void selectLevel() {
    	String name = inputOutput("\nPlease enter your nick name: ");
    	System.out.println("You will play with the nick name : "+name);
    	
    	Level level=new Level();
    	level.printChooses();

	}


    private void setTwoPlayer(){
    	name1 = inputOutput("\nPlease enter first player's name: ");
    	name2 = inputOutput("\nPlease enter second player's name: ");
    	System.out.println("Players are "+name1 + " and " +name2);
    }
    
	private  void wrongChoice() {
    	System.out.println("You should choose to play one player game" +
    			" because our main use case that we implement in this code is that." +
    			"You exited.");
    	System.exit(0);
	}

	public  String inputOutput(String message) {
        System.out.println(message);
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String returnString = "";
	    try {
	        returnString = br.readLine();
	    }
	    catch (IOException e){
	        System.out.println("Error reading in value");
	        initMenu();
	    }
	    return returnString;
    }
    
    protected int stringToInt(String value) {
        int returnInt = -1;
        try {
            returnInt = Integer.parseInt(value);
        }
        catch (NumberFormatException e) {
            System.out.println("Please input an integer\n");
        }
        return returnInt;
    }
}
